import { reactive,onMounted } from 'vue';
import axios from 'axios';
import type { DogItem } from '@/types';

export default function useDog() {
  // 修改为明确类型的数组
  const dogList = reactive<DogItem[]>([])

  async function getDogList() {
    try {
      const res = await axios.get('https://dog.ceo/api/breeds/image/random')
      dogList.push({
        id: dogList.length + 1,
        url: res.data.message
      })
    } catch (error) {
      console.log(error)
    }
  }
  onMounted(()=>{
    getDogList()
    console.log('Dog挂载完成')
  })
  // 返回数据
  return {dogList,getDogList}
}